package bdcin.mineracao;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;

import org.pdfbox.pdfparser.PDFParser;
import org.pdfbox.pdmodel.PDDocument;
import org.pdfbox.util.PDFTextStripper;

import bdcin.util.Constants;

public class PdfParser {

	
	public static void converterPDF(String caminhoOrigem) {

		File f = new File(caminhoOrigem);
		
		FileInputStream is = null;
		try {
			is = new FileInputStream(f);
		} catch (IOException e) {
			e.printStackTrace();
		}

		PDDocument pdfDocument = null;

		try {

			PDFParser parser = new PDFParser(is);
			parser.parse();
			pdfDocument = parser.getPDDocument();
			PDFTextStripper stripper = new PDFTextStripper();
			String conteudo = stripper.getText(pdfDocument);
			
		
		FileOutputStream saida;
		PrintStream fileSaida;
		
		try {
			saida = new FileOutputStream(Constants.localDocs+"/arq1.doc");
			fileSaida = new PrintStream(saida);
			fileSaida.print(conteudo);
		} catch (Exception e) {
			System.err.println(e);
		}

		} catch (IOException e) {
		} catch (Throwable e) {
			e.printStackTrace();
		} finally {
			if (pdfDocument != null) {
				try {
					pdfDocument.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
		
	}

}
